﻿<%@ WebHandler Language="C#" Class="Upload" %>

using System.IO;
using System.Web;
using DB;

public class Upload : IHttpHandler 
{   
    public void ProcessRequest (HttpContext context) 
    {
        var files = context.Request.Files;
        var c = files.Count;     
        if (c > 0)
        {

            using (var db = DBUtils.CreateDataAbstaction())
            {
                for (int i = 0; i < c; i++)
                {
                    var file = files[i];
                    var bytes = new BinaryReader(file.InputStream).ReadBytes((int) file.InputStream.Length);
                    db.MObjects.InsertOnSubmit(
                        new MObject
                        {
                            ParentAlbumRef = 1, 
                            Type = 0, 
                            Data = bytes
                        });
                }
                db.SubmitChanges();
            }

        }
    }
 
    public bool IsReusable { get { return true; } }
}